package com.etc.team2.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.etc.team2.bean.Station;
import com.etc.team2.service.StationService;

public class getStationServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	/**
	 * 根据用户搜索的站台名返回站台信息的Servlet
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		/*获取用户搜索的站台名，调用StationService中的getStation()方法
		 * 如果获取到站台信息，则调转到stationforuser.jsp，并发送站台信息过去
		 * 如果没有获取站台信息，返回错误页面stationerror.jsp
		 */
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		String stationName=request.getParameter("username");
			//new String(request.getParameter("username").getBytes("ISO-8859-1"),"utf-8");
		StationService stationService=new StationService();
		Station searchStation=stationService.getStation(stationName);
		if (searchStation!=null) {
			request.setAttribute("searchStation", searchStation);
			request.getRequestDispatcher("station.jsp").forward(request, response);
		} else {
			response.sendRedirect("error.jsp");

		}		
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request,response);
	}

}
